package com.tfjybj.itoo.exam.provider.controller;

import com.dmsdbj.itoo.tool.business.ItooResult;
import com.tfjybj.itoo.exam.model.*;
import com.tfjybj.itoo.exam.provider.service.PracticeStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author: 王雪芬
 * @Description: 随堂小练学生端
 * @Date: Created in 9:04 2019/1/27
 */
@Slf4j
@Api(tags = {"PracticeStudent接口"})
@RequestMapping(value = "/PracticeStudent")
@RestController
public class PracticeStudentController {
    @Resource
    private PracticeStudentService practiceStudentService;

    /**
     * 根据学生学号查询实习系统正在进行的考试（小练）
     * @author 谷海涛
     * @since 2019年7月7日21:07:35
     * @param studentCode
     * @return
     */

    @ApiOperation(value = "根据学生学号查询实习系统的考试")
    @RequestMapping(value = "/selectLittlePractice/{studentCode}", method = RequestMethod.GET)
    public ItooResult selectLittlePractice(@ApiParam(value = "学生学号",required = true) @PathVariable String studentCode){
        List<ExamineeModel> examinationModelList = practiceStudentService.selectLittlePractice(studentCode);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功",examinationModelList);
    }


    /**
     * 根据学生id查询正在进行的考试（小练）
     * @author 于云秀
     * @since 2019年1月27日11:43:35
     * @param userId
     * @return
     */

    @ApiOperation(value = "根据学生id查询正在进行的考试")
    @RequestMapping(value = "/selectNowExam/{userId}", method = RequestMethod.GET)
    public ItooResult selectNowExam(@ApiParam(value = "学生id",required = true) @PathVariable String userId){
      List<ExaminationModel> examinationModelList = practiceStudentService.selectNowExam(userId);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功",examinationModelList);
    }

    /**
     * 目前考试答题（小练）
     * @author 王雪芬
     * @since 2019年1月27日11:43:35
     * @param userId
     * @return
     */

    @ApiOperation(value = "根据学生id查询正在进行的考试")
    @RequestMapping(value = "/selectNowExamQuestion/{userId}", method = RequestMethod.GET)
    public ItooResult selectNowExamQuestion(@ApiParam(value = "学生id",required = true) @PathVariable String userId){
        //  Map<String, List<ExaminationModel>> 课程名称,小练
        Map<String, List<ExaminationModel>> examinationModelMap = practiceStudentService.selectNowExamQuestion(userId);

        return ItooResult.build(ItooResult.SUCCESS, "查询成功",examinationModelMap);
    }


    /**
     * 目前考试答题（小练）
     * @author 谷海涛
     * @since 2019年7月18日10:58:30
     * @param studentCode
     * @return
     */

    @ApiOperation(value = "根据学生学号查询实习系统考试的名称")
    @RequestMapping(value = "/queryPracticeNowExamQuestion/{studentCode}", method = RequestMethod.GET)
    public ItooResult queryPracticeNowExam(@ApiParam(value = "学生学号",required = true) @PathVariable String studentCode){
        //  Map<String, List<ExaminationModel>> 课程名称,小练
       // List<ExaminationModel> examinationModelMap = practiceStudentService.queryPracticeNowExamQuestion(studentCode);
        Map<String, List<ExaminationModel>> examinationModelMapPra = practiceStudentService.queryPracticeNowExamQuestion(studentCode);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功",examinationModelMapPra);
    }

    /**
     * 根据学号查询所有成绩，实习系统（小练）
     * @author 谷海涛
     * @since 2019年7月24日11:32:30
     * @param studentCode
     * @return
     */
    @ApiOperation(value="随堂小练-根据学号查询所有成绩")
    @GetMapping(value = "/selectStudentScoreByStudentCode/{studentCode}")
    public ItooResult selectStudentScoreByStudentCode (@ApiParam(name="studentCode" ,value = "学号",required = true)@PathVariable String studentCode){
        if (studentCode != null){
            Map<String,List<StudentScoreLittlePracticeModel>> listStringMap = practiceStudentService.selectStudentScoreByStudentCode(studentCode);
            if (listStringMap != null){
                return ItooResult.build(ItooResult.SUCCESS,"查询成功",listStringMap);
            }else{
                return ItooResult.build(ItooResult.SUCCESS,"该学生没有成绩");
            }
        }else {
            return ItooResult.build(ItooResult.FAIL,"学生学号不能为空");
        }

    }
    /**
     * 根据学生学号，考试类型和考试状态查询学号对应的课程名称、考试名称、考试成绩
     * @param studentId
     * @param examType
     * @param examState
     * @author 杨月娥-2019年1月27日
     * @return
     */
    @ApiOperation(value="随堂小练-查询成绩")
    @GetMapping(value = "/selectStudentScoreByStudentIdExam/{studentId}/{examType}/{examState}")
    public ItooResult selectStudentScoreByStudentIdExam (@ApiParam(name="studentId" ,value = "学号",required = true)@PathVariable String studentId,
                                                       @ApiParam(name="examType",value = "考试类型",required = true)@PathVariable int examType,
                                                       @ApiParam(name = "examState",value = "考试状态",required = true)@PathVariable int examState){
       if (studentId != null){
           Map<String,List<StudentScoreLittlePracticeModel>> listStringMap = practiceStudentService.selectStudentScoreByStudentIdExam(studentId,examType,examState);
           if (listStringMap != null){
               return ItooResult.build(ItooResult.SUCCESS,"查询成功",listStringMap);
           }else{
               return ItooResult.build(ItooResult.SUCCESS,"该学生没有成绩");
           }
       }else {
           return ItooResult.build(ItooResult.FAIL,"学生ID不能为空");
       }

    }
/**
 * 根据学生学号，考试类型和考试状态查询学号对应的课程名称、考试名称、考试成绩
 * @param studentId
 * @param examType
 * @param examState
 * @author 杨海云-2019年1月27日
 * @return
 */
@ApiOperation(value="随堂小练-查询成绩")
@GetMapping(value = "/selectStudentScoreBystudentId/{studentId}/{examType}/{examState}")
public ItooResult selectStudentScoreBystudentId (@ApiParam(name="studentId" ,value = "学号",required = true)@PathVariable String studentId,
                                                   @ApiParam(name="examType",value = "考试类型",required = true)@PathVariable int examType,
                                                   @ApiParam(name = "examState",value = "考试状态",required = true)@PathVariable int examState){
    Map<String, List<PracticeTeacherModel>> practiceTeacherModelMap = practiceStudentService.selectStudentScoreBystudentId(studentId,examType,examState);
    if (practiceTeacherModelMap != null){
        return ItooResult.build(ItooResult.SUCCESS,"查询成功",practiceTeacherModelMap);
    }else{
        return ItooResult.build(ItooResult.SUCCESS,"该学生没有成绩");
    }
}


    /**
     * 根据考生ID和考场ID和判分状态查询对应的题型名称和题干
     * @param examineeId
     * @param examinationId
     * @author 杨月娥-2019年1月27日
     * @return
     */
    @ApiOperation(value = "随堂小练——查询题干和题型")
    @GetMapping(value = "/selectExamQuestionTypeAndQuestionContent/{examineeId}/{examinationId}")
    public ItooResult selectExamQuestionTypeAndQuestionContent(@ApiParam(name = "examineeId",value = "考生ID",required = true)@PathVariable String examineeId,
                                                               @ApiParam(name = "examinationId",value = "考试ID",required = true)@PathVariable String examinationId){
       if (examinationId != null && examineeId !=null){
           Map<String,List<PaperRecordModel>> map = practiceStudentService.selectExamQuestionTypeAndQuestionContent(examineeId,examinationId);
           if (map != null){
               return ItooResult.build(ItooResult.SUCCESS,"查询成功",map);
           }else {
               return ItooResult.build(ItooResult.SUCCESS,"当前小练下没有题型和题干");
           }
       }else {
           return  ItooResult.build(ItooResult.FAIL,"考试ID和考生ID不能为空");
       }


    }

    /**
     * 交卷汇总单个学生成绩
     * @param examineeId
     * @param examinationId
     * @author 王雪芬-2019年1月27日
     * @return
     */
    @ApiOperation(value = "随堂小练——交卷汇总学生成绩")
    @GetMapping(value = "/sumExameeIdScore/{examineeId}/{examinationId}")
    public ItooResult sumExamIdScore(@ApiParam(name = "examineeId",value = "考生ID",required = true)@PathVariable String examineeId,
                                                               @ApiParam(name = "examinationId",value = "考试ID",required = true)@PathVariable String examinationId){
        if (examineeId ==null || examinationId ==null ){
            log.warn("当前小练汇总成绩失败,examineeId-{},examinationId-{}",examineeId,examinationId);
            return ItooResult.build(ItooResult.SUCCESS,"当前小练汇总成绩失败");
        }
        boolean flag = practiceStudentService.sumExamIdScore(examineeId,examinationId);
        if (flag){
            return ItooResult.build(ItooResult.SUCCESS,"查询成功",flag);
        }else {
            return ItooResult.build(ItooResult.SUCCESS,"当前小练汇总成绩失败");
        }
    }

    /**
     * 不改变交卷状态汇总单个学生成绩
     * @param examineeId
     * @param examinationId
     * @author 谷海涛-2019年7月24日
     * @return 成功或失败
     */
    @ApiOperation(value = "随堂小练——不改变交卷转态汇总学生成绩，实习系统")
    @GetMapping(value = "/sumExameeIdScorePra/{examineeId}/{examinationId}")
    public ItooResult sumExamIdScorePra(@ApiParam(name = "examineeId",value = "考生ID",required = true)@PathVariable String examineeId,
                                     @ApiParam(name = "examinationId",value = "考试ID",required = true)@PathVariable String examinationId){
        if (examineeId ==null || examinationId ==null ){
            log.warn("当前小练汇总成绩失败,examineeId-{},examinationId-{}",examineeId,examinationId);
            return ItooResult.build(ItooResult.SUCCESS,"当前小练汇总成绩失败");
        }
        boolean flag = practiceStudentService.sumExamIdScorePra(examineeId,examinationId);
        if (flag){
            return ItooResult.build(ItooResult.SUCCESS,"查询成功",flag);
        }else {
            return ItooResult.build(ItooResult.SUCCESS,"当前小练汇总成绩失败");
        }
    }

    /**
     * 获取学生是否交卷
     * @param examineeId
     * @author 王雪芬-2019年1月27日
     * @return
     */
    @ApiOperation(value = "随堂小练——获取学生是否交卷")
    @GetMapping(value = "/getExamineeStatus/{examineeId}/{examinationId}")
    public ItooResult getExamineeStatus(@ApiParam(name = "examineeId",value = "考生ID",required = true)@PathVariable String examineeId,
                                        @ApiParam(name = "examinationId",value = "考试ID",required = true)@PathVariable String examinationId){
        if(examineeId==null){
            log.warn("查询学生是否交卷examineeId is null");
            return ItooResult.build(ItooResult.SUCCESS,"获取考生状态失败");
        }
            boolean flag = practiceStudentService.getExamineeStatus(examineeId,examinationId);
            return ItooResult.build(ItooResult.SUCCESS,"获取考生状态",flag);
    }
}
